﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
@model TaoPortal.Areas.Admin.Models.SimplePageModel
<ul class="breadcrumb">
    <li><a href="#">首页</a> <span class="divider">/</span></li>
    <li><a href="#">内容管理</a> <span class="divider">/</span></li>
    <li class="active">单页管理</li>
</ul>
<form tabindex="0" class="form-horizontal" id="searchForm">
    <table style="margin-bottom: 5px; width: 100%">
        <tr>
            <td style="width: 240px;">页面标识：@Html.TextBoxFor(x => x.Searcher.PKey, new { @class = "input-normal" })</td>
            <td style="width: 240px;">页面标题：@Html.TextBoxFor(x => x.Searcher.PTitle, new { @class = "input-normal" })</td>
            <td style="width: 320px;">创建日期：@Html.TextBoxFor(x => x.Searcher.StartDate, new { @class = "calendar" }) - @Html.TextBoxFor(x => x.Searcher.EndDate, new { @class = "calendar" })</td>
            <td>
                <button class="button button-small" id="btnSearch" type="submit">搜索</button>
                <button style="float: right" class="button button-small button-primary" id="btnCreate" type="button">新建</button></td>
        </tr>
    </table>
</form>
<div id="grid">
</div>
<script type="text/javascript">
    var Grid = BUI.Grid,
    Store = BUI.Data.Store,
    columns = [
      { title: '标题', width: 200, sortable: false, dataIndex: 'PTitle' },
      { title: '页面标识', width: 80, sortable: false, dataIndex: 'PKey' },
      { title: '链接地址', sortable: false, dataIndex: 'PUrl' },
      { title: '创建时间', width: 150, sortable: false, dataIndex: 'CreateTime' },
      {
          title: '操作', width: 80, sortable: false, dataIndex: 'ID',
          renderer: function (value, obj) {
              return '<span class="grid-command" onclick="EditPage(\'' + value + '\')">编辑</span><span class="grid-command" onclick="DeletePage(\'' + value + '\')" >删除</span>';
          }
      }
    ];
    //加载列表
    var store = new Store({
        url: '/Admin/SimplePage/AjaxGetList',
        proxy: {
            limitParam: 'pageSize',
            method: 'post'
        },
        autoLoad: true,
        pageSize: 10
    }),
    grid = new Grid.Grid({
        render: '#grid',
        loadMask: true,
        forceFit: true,
        plugins: [Grid.Plugins.AutoFit],
        columns: columns,
        store: store,
        bbar: {
            pagingBar: true
        }
    });
    grid.render();
    //搜索
    var form = $('#searchForm')[0];
    $(form).on('submit', function (ev) {
        ev.preventDefault();
        var obj = BUI.FormHelper.serializeToObject(form);
        obj.pageIndex = 0;
        obj.start = 0;
        store.load(obj);
    });
    //日期控件
    BUI.use('bui/calendar', function (Calendar) {
        var datepicker = new Calendar.DatePicker({
            trigger: '.calendar',
            //maxDate: '2014-01-01',
            //minDate: '2013-7-25',
            autoRender: true
        });
    });
    var Overlay = BUI.Overlay
    var dialog = null;
    //新建页面
    $('#btnCreate').click(function () {
        dialog = new Overlay.Dialog({
            title: '单页管理->新建页面',
            width: 900,
            closeAction: 'destroy',
            height: 500,
            buttons: [],
            bodyStyle: { 'padding': '0px' },
            bodyContent: '<iframe frameborder="0" style="width:890px;height:390px" src="/Admin/SimplePage/AddPage"></iframe>'
        });
        dialog.show();
    })
    function EditPage(id) {
        dialog = new Overlay.Dialog({
            title: '单页管理->编辑页面',
            width: 900,
            closeAction: 'destroy',
            height: 500,
            buttons: [],
            bodyStyle: { 'padding': '0px' },
            bodyContent: '<iframe frameborder="0" style="width:890px;height:390px" src="/Admin/SimplePage/EditPage/' + id + '"></iframe>'
        });
        dialog.show();
    }

    function DeletePage(id) {
        if (confirm('确定删除？')) {
            $.ajax({
                type: 'post',
                url: '/Admin/SimplePage/DeletePage/' + id,
                success: function () {
                    $('#btnSearch').trigger('click');
                }
            })
        }
    }
    function SubmitSuccess() {
        alert('提交成功！')
        dialog.close();
        $('#btnSearch').trigger('click');
    }
    function CloseWin() {
        dialog.close();
    }
</script>
